var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		options: [],
		datalist:[],
    pagenum: 1,
    id:0,
    total:0,
    idd:0,
    chouhao:0,
	},
	_onLoad: function () {
    var that = this
    const idd = that.options.id
    this.data.idd = that.options.id
    // that.setData({
    //   id: idd
    // })
    console.log('optt333',that.options,that.options.id)
		this.getDataList()
	},
	getDataList: function(){
		var that = this
		var pagenum = that.data.pagenum
		var id = that.options && that.options.id ? that.options.id : 0;
		
		$.post('yuxun/baomingdetail', {id:id,pagenum:pagenum}, function (res) {
      var data = res.data
      console.log('报名情况',res)
			if(pagenum == 1){
				that.setData({ datalist: data,id:data.id,paytotal:res.pay_total,total:res.baoming_total,chouhao:res.ischouhao});
				if (data.length == 0){
					$.showEmpty('暂无记录','/images/empty2.png');
				}
			}else{
				if (data.length == 0){
					that.setData({$nomoreData:true});
				}else{
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
			wx.setNavigationBarTitle({ title: res.title})
		});
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData){
			this.setData({ pagenum: this.data.pagenum+1 })
			this.getDataList();
		}
  },
  // 退款
  refund(e){
    console.log('是否抽号',this.data.chouhao)
    if(this.data.chouhao == 1){
      wx.showModal({
        title: '提示',
        content: '已抽号，不可退款',
        complete: (res) => {
          if (res.cancel) {
            
          }
      
          if (res.confirm) {
            
          }
        }
      })
      return
    }
    console.log('点击退款',e.currentTarget.dataset.id)
    $.post('yuxun/moneyback',{id:e.currentTarget.dataset.id},res=>{
      this.getDataList()
    })
  }
}));